(function($) {
    $.fn.slider = function(options) {
        var settings = {
            width : 738,
            height : 298,
            delay : 3000
        };
        if (options) {
            $.extend(settings, options);
        }
        var source = this;
        var imgs = $(source).find('img');
        imgs.parent().hide();// 隐藏所有图片
        var imgCount = imgs.size();
        var showImgIndex = -1;
        var alt = new Array;
        var altDis = '';
        $(source).css({
            width : settings.width,
            height : settings.height
        });
        // 获取图片所有alt信息
        var imgAlt = function() {
            altDis += '<ul id="altDis">';
            $.each(imgs, function(i, n) {
                alt[i] = $(this).attr("alt");
                altDis += '<li>' + alt[i] + '</li>';
            });
            altDis += '</ul>';
        }
        var imgShow = function() {
            showImgIndex++;
            imgs.parent().hide();// 隐藏所有图片
            $(source).find("#altDis>li").removeClass('on');
            $(source).find("a:eq(" + showImgIndex + ")").fadeIn("normal");
            $(source).find("#altDis>li:eq(" + showImgIndex + ")").addClass('on');
            if (showImgIndex >= imgCount - 1) {
                showImgIndex = -1;
            }
        }
        imgAlt();// 活动信息获取
        imgShow();// 默认显示
        $("#p_tit").html(altDis);// 添加活动
        var imgSlider = imgCount > 1 ? setInterval(imgShow, settings.delay)
            : null;
        $(source).find("#altDis>li:eq(0)").addClass('on');
        // 加载入鼠标悬停事件
        $(source).find("#altDis>li").mouseover(
            function() {
                if (imgCount > 1) {
                    $(source).find("a").stop();//BUG 修复动画
                    clearInterval(imgSlider);
                    // 处理悬停
                    $(source).find("#altDis>li").removeClass('on');
                    $(this).addClass('on');
                    showImgIndex = $("#altDis>li").index(this);
                    $(source).find("#altDis>li:eq(" + showImgIndex + ")")
                        .addClass('on');
                    // 设置
                    imgs.parent().hide();// 隐藏所有图片
                    $(source).find("a:eq(" + showImgIndex + ")").fadeIn(
                        "normal");
                }
            });
        $(source).find("#altDis>li").mouseout(function() {
            if (showImgIndex == imgCount - 1) {
                showImgIndex = -1;
            }
            if (imgCount > 1) {
                imgSlider = setInterval(imgShow, settings.delay);
            }
        });
    }
}(jQuery));